package LeetCode._顺序刷题;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: yqy
 * @Date: 2022/06/06/17:20
 * @Description:
 */
public class _205 {
    public static void main(String[] args) {
        _205 v = new _205();
        boolean b = v.isIsomorphic("add", "egg");
        System.out.println(b);
    }
    public boolean isIsomorphic(String s, String t) {
        if (s.length()!=t.length()){
            return false;
        }
        Map<Character,Character> s2t=new HashMap();
        Map<Character,Character> t2s=new HashMap();
        int i=0;
        while(i<s.length()){
            char tchar = t.charAt(i) , schar = s.charAt(i);
            if ((s2t.containsKey(schar) && s2t.get(schar)!=tchar)||(t2s.containsKey(tchar) && t2s.get(tchar)!=schar)){
                return false;
            }
            s2t.put(schar,tchar);
            t2s.put(tchar,schar);
            i++;
        }
        return true;
    }

}
